package com.cheyunkeji.er.activity.auction;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.Constants;
import com.cheyun.netsalev3.MyApplication;
import com.cheyunkeji.er.adapter.ViewPagerAdapter;
import com.cheyunkeji.er.adapter.auction.BaojiaRecordAdapter;
import com.cheyunkeji.er.base.BaseActivity;
import com.cheyunkeji.er.bean.auction.AuctionResultDetail;
import com.cheyunkeji.er.bean.auction.AuctionRollbackBean;
import com.cheyunkeji.er.bean.auction.BaojiaRecordItem;
import com.cheyunkeji.er.bean.auction.DetectionCount;
import com.cheyunkeji.er.bean.auction.XunJiaResultDetail;
import com.cheyunkeji.er.bean.evaluate.EvaluateDetailResult2;
import com.cheyunkeji.er.http.ApiClient;
import com.cheyunkeji.er.http.HttpConstants;
import com.cheyunkeji.er.http.RespCallback;
import com.cheyunkeji.er.utils.StringUtils;
import com.cheyunkeji.er.utils.TimeUtils;
import com.cheyunkeji.er.utils.countdown.CountDownTask;
import com.cheyunkeji.er.utils.countdown.CountDownTimers;
import com.cheyunkeji.er.view.AutoScrollViewPager;
import com.cheyunkeji.er.view.SDialog;
import com.cheyunkeji.er.view.SToast;
import com.cheyunkeji.er.view.TranslucentScrollView;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Request;

public class XunJiaDetailActivity extends BaseActivity implements ViewPager.OnPageChangeListener, View.OnClickListener, TranslucentScrollView.mOnScrollChangedListener, SDialog.SDialog2Listener {

    private static final String TAG = XunJiaDetailActivity.class.getSimpleName();
    private final int CODE_START_LOOP_AUCTION_LIST = 0X1308;
    @BindView(R.id.vp_img)
    AutoScrollViewPager mViewPager;
    @BindView(R.id.tv_indicator)
    TextView tvIndicator;
    @BindView(R.id.activity_xun_jia_detail)
    RelativeLayout activityXunJiaDetail;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.et_baojia)
    EditText etBaojia;
    @BindView(R.id.rl_my_baojia)
    RelativeLayout rlMyBaojia;
    @BindView(R.id.tv_commit_price)
    TextView tvCommitPrice;
    @BindView(R.id.tv_state)
    TextView tvState;
    @BindView(R.id.tv_car_desc)
    TextView tvCarDesc;
    @BindView(R.id.tv_md_title)
    TextView tvMdTitle;
    @BindView(R.id.tv_company_name)
    TextView tvCompanyName;
    @BindView(R.id.tv_time_state)
    TextView tvTimeState;
    @BindView(R.id.iv_arrow_right)
    ImageView ivArrowRight;
    @BindView(R.id.tv_time_left)
    TextView tvTimeLeft;
    @BindView(R.id.lv_baojia_record)
    ListView lvBaojiaRecord;
    @BindView(R.id.rl_car_archive)
    RelativeLayout rlCarArchive;
    @BindView(R.id.tv_drive_miles)
    TextView tvDriveMiles;
    @BindView(R.id.tv_license_time)
    TextView tvLicenseTime;
    @BindView(R.id.tv_paifang_standard)
    TextView tvPaifangStandard;
    @BindView(R.id.tv_emission)
    TextView tvEmission;
    @BindView(R.id.tv_csgj)
    TextView tvCsgj;
    @BindView(R.id.rl_csgj)
    RelativeLayout rlCsgj;
    @BindView(R.id.tv_wg)
    TextView tvWg;
    @BindView(R.id.rl_wg)
    RelativeLayout rlWg;
    @BindView(R.id.tv_fdjc)
    TextView tvFdjc;
    @BindView(R.id.rl_fdjc)
    RelativeLayout rlFdjc;
    @BindView(R.id.tv_jsc)
    TextView tvJsc;
    @BindView(R.id.rl_jsc)
    RelativeLayout rlJsc;
    @BindView(R.id.tv_qd)
    TextView tvQd;
    @BindView(R.id.rl_qd)
    RelativeLayout rlQd;
    @BindView(R.id.tv_ls)
    TextView tvLs;
    @BindView(R.id.rl_ls)
    RelativeLayout rlLs;
    @BindView(R.id.tv_gnx_lbj)
    TextView tvGnxLbj;
    @BindView(R.id.rl_gnx_lbj)
    RelativeLayout rlGnxLbj;
    @BindView(R.id.tv_dp)
    TextView tvDp;
    @BindView(R.id.rl_dp)
    RelativeLayout rlDp;
    @BindView(R.id.sv_detail_display)
    TranslucentScrollView svDetailDisplay;
    @BindView(R.id.tv_my_price)
    TextView tvMyPrice;
    @BindView(R.id.price_unit)
    TextView priceUnit;
    @BindView(R.id.iv_icon)
    ImageView ivIcon;
    @BindView(R.id.rl_time_diaplay)
    RelativeLayout rlTimeDiaplay;
    @BindView(R.id.ll_baojia_record)
    LinearLayout llBaojiaRecord;
    @BindView(R.id.iv_icon_a)
    ImageView ivIconA;
    @BindView(R.id.tv_icon_text_desc1)
    TextView tvIconTextDesc1;
    @BindView(R.id.iv_icon_b)
    ImageView ivIconB;
    @BindView(R.id.tv_icon_text_desc2)
    TextView tvIconTextDesc2;
    @BindView(R.id.iv_icon_c)
    ImageView ivIconC;
    @BindView(R.id.tv_icon_text_desc3)
    TextView tvIconTextDesc3;
    @BindView(R.id.iv_icon_d)
    ImageView ivIconD;
    @BindView(R.id.tv_icon_text_desc4)
    TextView tvIconTextDesc4;
    @BindView(R.id.iv_red_rec)
    ImageView ivRedRec;
    @BindView(R.id.arrow_right_1)
    ImageView arrowRight1;
    @BindView(R.id.arrow_right_2)
    ImageView arrowRight2;
    @BindView(R.id.arrow_right_3)
    ImageView arrowRight3;
    @BindView(R.id.arrow_right_4)
    ImageView arrowRight4;
    @BindView(R.id.arrow_right_5)
    ImageView arrowRight5;
    @BindView(R.id.arrow_right_6)
    ImageView arrowRight6;
    @BindView(R.id.arrow_right_7)
    ImageView arrowRight7;
    @BindView(R.id.arrow_right_8)
    ImageView arrowRight8;
    @BindView(R.id.tv_baojia)
    TextView tvBaojia;
    @BindView(R.id.bottom_layout)
    RelativeLayout bottomLayout;
    @BindView(R.id.tv_01)
    TextView tv01;
    @BindView(R.id.tv_02)
    TextView tv02;
    @BindView(R.id.tv_my_top_baojia)
    TextView tvMyTopBaojia;
    @BindView(R.id.tv_03)
    TextView tv03;
    @BindView(R.id.tv_04)
    TextView tv04;
    @BindView(R.id.tv_got_price)
    TextView tvGotPrice;
    @BindView(R.id.rl_two_price)
    RelativeLayout rlTwoPrice;
    //        @BindView(R.id.v_topbar)
//        TopBar vTopbar;
//    @BindView(R.id.tb_head)
//    Toolbar tbHead;
    @BindView(R.id.rl_topbar)
    RelativeLayout rlTopBar;
    @BindView(R.id.iv_back_home)
    ImageView ivBackHome;
    @BindView(R.id.tv_transfer_pay)
    TextView tvTransferPay;
    @BindView(R.id.ll_transfer_pay)
    LinearLayout llTransferPay;
    @BindView(R.id.tv_deliver_time)
    TextView tvDeliverTime;
    @BindView(R.id.baoliu_text)
    TextView baoliu_text;
    private ViewPagerAdapter mAdapter;
    private ArrayList<String> urlList;
    private ArrayList<BaojiaRecordItem> baojiaRecordList;
    private BaojiaRecordAdapter bjRecordAdapter;
    private Intent intent;
    //    倒计时任务
    private CountDownTask mCountDownTask;

    //    两种数据格式：1.竞拍结果 2.询价结果
    private AuctionResultDetail auctionResultDetail;

    private XunJiaResultDetail xunJiaResultDetail;

    //    详情信息类别，8种
    private int resultType;

    private HandlerThread auctionHandlerThread;
    private Handler auctionHandler;

    @SuppressLint("HandlerLeak")
    private Handler uiRefreshHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            baoliu_text.setVisibility(View.GONE);
            switch (resultType) {

                case Constants.RESULT_TYPE_AUCTION_ON_PROCESS:

                    if (null == auctionResultDetail) {
                        return;
                    }


                    tvState.setText("竞拍中");
                    tvTimeState.setText("距竞拍结束");
                    bottomLayout.setVisibility(View.VISIBLE);
                    llBaojiaRecord.setVisibility(View.VISIBLE);
                    etBaojia.setVisibility(View.GONE);
                    tvBaojia.setVisibility(View.VISIBLE);
                    tvCommitPrice.setEnabled(true);

                    showDeliverCarInfo(true, auctionResultDetail.getBuyerbear(), auctionResultDetail.getEddate());

                    //如果当前最高报价为0，则当前出价为 起拍价+最小增幅
                    if (!TextUtils.isEmpty(String.valueOf(auctionResultDetail.getMax_callprice())) && 0 != auctionResultDetail.getMax_callprice()) {
                        tvBaojia.setText(StringUtils.getFormatedWith2Bit((auctionResultDetail.getMax_callprice() + auctionResultDetail.getIncrease()) / 10000F));
                    } else {
//                        tvBaojia.setText(StringUtils.getFormatedWith2Bit((auctionResultDetail.getSprice() + auctionResultDetail.getIncrease()) / 10000F));
                        tvBaojia.setText(StringUtils.getFormatedWith2Bit((auctionResultDetail.getSprice()) / 10000F));
                    }


                    initBackThread();

//                    开始轮询
                    auctionHandler.sendEmptyMessage(CODE_START_LOOP_AUCTION_LIST);

                    mCountDownTask = CountDownTask.create()
                            .until(tvTimeLeft, CountDownTask.elapsedRealtime() + Long.valueOf(auctionResultDetail.getEtime()) * 1000 - System.currentTimeMillis(), 1000, new CountDownTimers.OnCountDownListener() {
                                @Override
                                public void onTick(View view, long millisUntilFinished) {
                                    ((TextView) view).setText(TimeUtils.leftMillis2String(millisUntilFinished));
                                }

                                @Override
                                public void onFinish(View view) {
//                                  时间截止，获取最新状态
                                    Log.e(TAG, "onFinish: 竞拍时间截止！！！");
                                    loadAuctionResultDetail(getIntent().getStringExtra("tid"));
                                }
                            });


                    displayCommonUi(auctionResultDetail.getBrand_name(), auctionResultDetail.getSeries_name(), auctionResultDetail.getSpec_name(), auctionResultDetail.getChannel_name(),
                            auctionResultDetail.getVerank_name(), auctionResultDetail.getIsacc(), auctionResultDetail.getIsws(), auctionResultDetail.getIsburn(),
                            auctionResultDetail.getMileage(), auctionResultDetail.getLicdate(), auctionResultDetail.getEmission_name(), auctionResultDetail.getDisplace(), auctionResultDetail.getDispunit(),
                            auctionResultDetail.getDetection_count(), auctionResultDetail.getImage());

                    break;

                case Constants.RESULT_TYPE_AUCTION_PREPROCESS:

                    if (null == auctionResultDetail) {
                        return;
                    }

//                  预拍通知信息进来，根据时间判断预拍是否结束
                    if (Long.valueOf(auctionResultDetail.getEtime()) * 1000 <= System.currentTimeMillis()) {
                        resultType = Constants.RESULT_TYPE_AUCTION_ON_PROCESS;
                        loadAuctionResultDetail(getIntent().getStringExtra("tid"));
                        return;
                    }

                    showDeliverCarInfo(true, auctionResultDetail.getBuyerbear(), auctionResultDetail.getEddate());

                    tvState.setText("预拍中");
                    tvTimeState.setText("距竞拍开始");

                    bottomLayout.setVisibility(View.VISIBLE);
                    etBaojia.setVisibility(View.GONE);
                    tvBaojia.setVisibility(View.VISIBLE);
                    tvMyPrice.setText("起拍价格");

                    if (!TextUtils.isEmpty(String.valueOf(auctionResultDetail.getMax_callprice())) && 0 != auctionResultDetail.getMax_callprice())
                        tvBaojia.setText(StringUtils.getFormatedWith2Bit((auctionResultDetail.getMax_callprice()) / 10000F));
                    else
                        tvBaojia.setText(StringUtils.getFormatedWith2Bit((auctionResultDetail.getSprice()) / 10000F));

                    mCountDownTask = CountDownTask.create()
                            .until(tvTimeLeft, CountDownTask.elapsedRealtime() + Long.valueOf(auctionResultDetail.getStime()) * 1000 - System.currentTimeMillis(), 1000, new CountDownTimers.OnCountDownListener() {
                                @Override
                                public void onTick(View view, long millisUntilFinished) {
                                    ((TextView) view).setText(TimeUtils.leftMillis2String(millisUntilFinished));
                                }

                                @Override
                                public void onFinish(View view) {

//                                  预拍结束后，进入竞拍状态
                                    resultType = Constants.RESULT_TYPE_AUCTION_ON_PROCESS;
                                    loadAuctionResultDetail(getIntent().getStringExtra("tid"));
                                }
                            });
                    displayCommonUi(auctionResultDetail.getBrand_name(), auctionResultDetail.getSeries_name(), auctionResultDetail.getSpec_name(), auctionResultDetail.getChannel_name(),
                            auctionResultDetail.getVerank_name(), auctionResultDetail.getIsacc(), auctionResultDetail.getIsws(), auctionResultDetail.getIsburn(),
                            auctionResultDetail.getMileage(), auctionResultDetail.getLicdate(), auctionResultDetail.getEmission_name(), auctionResultDetail.getDisplace(), auctionResultDetail.getDispunit(),
                            auctionResultDetail.getDetection_count(), auctionResultDetail.getImage());

                    break;

                case Constants.RESULT_TYPE_AUCTION_GOT:

                    if (null == auctionResultDetail) {
                        return;
                    }

                    tvState.setText("已得标");
                    tvTimeState.setText("竞拍结束");
                    tvTimeLeft.setText("已得标");
                    rlTimeDiaplay.setBackgroundColor(Color.parseColor("#6177a0"));

                    showDeliverCarInfo(true, auctionResultDetail.getBuyerbear(), auctionResultDetail.getEddate());

                    llBaojiaRecord.setVisibility(View.GONE);
                    bottomLayout.setVisibility(View.VISIBLE);
                    etBaojia.setVisibility(View.GONE);
                    tvBaojia.setVisibility(View.VISIBLE);
                    rlTimeDiaplay.setBackgroundColor(getResources().getColor(R.color.txt_level_2));
                    tvMyPrice.setText("得标价格：");
                    tvBaojia.setText(StringUtils.getFormatedWith2Bit((auctionResultDetail.getWinner_callprice()) / 10000F));
                    tvCommitPrice.setVisibility(View.GONE);

                    displayCommonUi(auctionResultDetail.getBrand_name(), auctionResultDetail.getSeries_name(), auctionResultDetail.getSpec_name(), auctionResultDetail.getChannel_name(),
                            auctionResultDetail.getVerank_name(), auctionResultDetail.getIsacc(), auctionResultDetail.getIsws(), auctionResultDetail.getIsburn(),
                            auctionResultDetail.getMileage(), auctionResultDetail.getLicdate(), auctionResultDetail.getEmission_name(), auctionResultDetail.getDisplace(), auctionResultDetail.getDispunit(),
                            auctionResultDetail.getDetection_count(), auctionResultDetail.getImage());

                    break;

                case Constants.RESULT_TYPE_AUCTION_LOST:

                    if (null == auctionResultDetail) {
                        return;
                    }

                    tvState.setText("已流标");
                    tvTimeState.setText("竞拍结束");
                    tvTimeLeft.setText("已流标");
                    rlTimeDiaplay.setBackgroundColor(Color.parseColor("#6177a0"));

                    showDeliverCarInfo(true, auctionResultDetail.getBuyerbear(), auctionResultDetail.getEddate());

                    bottomLayout.setVisibility(View.VISIBLE);
                    etBaojia.setVisibility(View.GONE);
                    tvBaojia.setVisibility(View.VISIBLE);
                    tvMyPrice.setText("我的最高报价：");
                    if (!TextUtils.isEmpty(String.valueOf(auctionResultDetail.getCallprice())) && 0 != auctionResultDetail.getCallprice()) {
                        tvBaojia.setText(StringUtils.getFormatedWith2Bit(auctionResultDetail.getCallprice() / 10000F));
                    }

                    tvCommitPrice.setVisibility(View.GONE);

                    displayCommonUi(auctionResultDetail.getBrand_name(), auctionResultDetail.getSeries_name(), auctionResultDetail.getSpec_name(), auctionResultDetail.getChannel_name(),
                            auctionResultDetail.getVerank_name(), auctionResultDetail.getIsacc(), auctionResultDetail.getIsws(), auctionResultDetail.getIsburn(),
                            auctionResultDetail.getMileage(), auctionResultDetail.getLicdate(), auctionResultDetail.getEmission_name(), auctionResultDetail.getDisplace(), auctionResultDetail.getDispunit(),
                            auctionResultDetail.getDetection_count(), auctionResultDetail.getImage());

                    break;

                case Constants.RESULT_TYPE_AUCTION_OTHERS_GOT:

                    if (null == auctionResultDetail) {
                        return;
                    }

                    tvState.setText("未得标");
                    tvTimeState.setText("竞拍结束");
                    tvTimeLeft.setText("未得标");
                    rlTimeDiaplay.setBackgroundColor(Color.parseColor("#6177a0"));

                    showDeliverCarInfo(true, auctionResultDetail.getBuyerbear(), auctionResultDetail.getEddate());

                    bottomLayout.setVisibility(View.VISIBLE);
                    rlMyBaojia.setVisibility(View.GONE);
                    rlTwoPrice.setVisibility(View.VISIBLE);
                    tvCommitPrice.setVisibility(View.GONE);

                    tvMyTopBaojia.setText(StringUtils.getFormatedWith2Bit(auctionResultDetail.getCallprice() / 10000F));
                    tvGotPrice.setText(StringUtils.getFormatedWith2Bit(auctionResultDetail.getWinner_callprice() / 10000F));

                    displayCommonUi(auctionResultDetail.getBrand_name(), auctionResultDetail.getSeries_name(), auctionResultDetail.getSpec_name(), auctionResultDetail.getChannel_name(),
                            auctionResultDetail.getVerank_name(), auctionResultDetail.getIsacc(), auctionResultDetail.getIsws(), auctionResultDetail.getIsburn(),
                            auctionResultDetail.getMileage(), auctionResultDetail.getLicdate(), auctionResultDetail.getEmission_name(), auctionResultDetail.getDisplace(), auctionResultDetail.getDispunit(),
                            auctionResultDetail.getDetection_count(), auctionResultDetail.getImage());

                    break;

                case Constants.RESULT_TYPE_BAOJIA_WAIT:

                    if (xunJiaResultDetail == null) {
                        return;
                    }

                    tvState.setText("询价中");
                    tvTimeState.setText("距询价结束");
                    bottomLayout.setVisibility(View.VISIBLE);
                    etBaojia.setVisibility(View.VISIBLE);
                    tvBaojia.setVisibility(View.GONE);
                    tvCommitPrice.setEnabled(true);

                    showDeliverCarInfo(false, "", xunJiaResultDetail.getEddate());

                    mCountDownTask = CountDownTask.create()
                            .until(tvTimeLeft, CountDownTask.elapsedRealtime() + Long.valueOf(xunJiaResultDetail.getEtime()) * 1000 - System.currentTimeMillis(), 1000, new CountDownTimers.OnCountDownListener() {
                                @Override
                                public void onTick(View view, long millisUntilFinished) {
                                    ((TextView) view).setText(TimeUtils.leftMillis2String(millisUntilFinished));
                                }

                                @Override
                                public void onFinish(View view) {

//                                  未报价，时间截止，进入未报价状态
                                    resultType = Constants.RESULT_TYPE_BAOJIA_NOT;
                                    loadXunjiaResultDetail(getIntent().getStringExtra("rid"));
                                }
                            });

                    displayCommonUi(xunJiaResultDetail.getBrand_name(), xunJiaResultDetail.getSeries_name(), xunJiaResultDetail.getSpec_name(), xunJiaResultDetail.getChannel_name(),
                            xunJiaResultDetail.getVerank_name(), xunJiaResultDetail.getIsacc(), xunJiaResultDetail.getIsws(), xunJiaResultDetail.getIsburn(),
                            String.valueOf(xunJiaResultDetail.getMileage()), xunJiaResultDetail.getLicdate(), xunJiaResultDetail.getEmission_name(), xunJiaResultDetail.getDisplace(), xunJiaResultDetail.getDispunit(),
                            xunJiaResultDetail.getDetection_count(), xunJiaResultDetail.getImage());

                    break;

                case Constants.RESULT_TYPE_BAOJIA_GAVE:

                    if (xunJiaResultDetail == null) {
                        return;
                    }

                    tvState.setText("已报价");
                    tvTimeState.setText("询价结束:");
                    tvTimeLeft.setText("已报价");
                    rlTimeDiaplay.setBackgroundColor(Color.parseColor("#6177a0"));

                    showDeliverCarInfo(false, "", xunJiaResultDetail.getEddate());

                    bottomLayout.setVisibility(View.VISIBLE);
                    etBaojia.setVisibility(View.GONE);
                    tvBaojia.setVisibility(View.VISIBLE);
                    tvCommitPrice.setVisibility(View.GONE);

                    Log.e(TAG, "handleMessage: 我的报价 ： " + xunJiaResultDetail.getCallprice());
                    tvBaojia.setText(StringUtils.getFormatedWith2Bit(xunJiaResultDetail.getCallprice() / 10000f));

                    displayCommonUi(xunJiaResultDetail.getBrand_name(), xunJiaResultDetail.getSeries_name(), xunJiaResultDetail.getSpec_name(), xunJiaResultDetail.getChannel_name(),
                            xunJiaResultDetail.getVerank_name(), xunJiaResultDetail.getIsacc(), xunJiaResultDetail.getIsws(), xunJiaResultDetail.getIsburn(),
                            String.valueOf(xunJiaResultDetail.getMileage()), xunJiaResultDetail.getLicdate(), xunJiaResultDetail.getEmission_name(), xunJiaResultDetail.getDisplace(), xunJiaResultDetail.getDispunit(),
                            xunJiaResultDetail.getDetection_count(), xunJiaResultDetail.getImage());
                    break;

                case Constants.RESULT_TYPE_BAOJIA_NOT:

                    if (xunJiaResultDetail == null) {
                        return;
                    }

                    tvState.setText("未报价");
                    tvTimeState.setText("询价结束");
                    tvTimeLeft.setText("未报价");
                    rlTimeDiaplay.setBackgroundColor(Color.parseColor("#6177a0"));

                    showDeliverCarInfo(false, "", xunJiaResultDetail.getEddate());

                    displayCommonUi(xunJiaResultDetail.getBrand_name(), xunJiaResultDetail.getSeries_name(), xunJiaResultDetail.getSpec_name(), xunJiaResultDetail.getChannel_name(),
                            xunJiaResultDetail.getVerank_name(), xunJiaResultDetail.getIsacc(), xunJiaResultDetail.getIsws(), xunJiaResultDetail.getIsburn(),
                            String.valueOf(xunJiaResultDetail.getMileage()), xunJiaResultDetail.getLicdate(), xunJiaResultDetail.getEmission_name(), xunJiaResultDetail.getDisplace(), xunJiaResultDetail.getDispunit(),
                            xunJiaResultDetail.getDetection_count(), xunJiaResultDetail.getImage());

                    break;

                default:
                    break;
            }
        }
    };


    /**
     * [车辆交车] 布局
     *
     * @param showTransferPay
     * @param buyerbear
     * @param eddate
     */
    private void showDeliverCarInfo(boolean showTransferPay, String buyerbear, String eddate) {

        if (!TextUtils.isEmpty(eddate)) {
            tvDeliverTime.setText(TimeUtils.millis2StringWithoutHMS(Long.valueOf(eddate) * 1000));
        }

        if (showTransferPay) {
            tvTransferPay.setText(TextUtils.equals(buyerbear, "1") ? "需要车商承担" : "不需要车商承担");
        } else {
            llTransferPay.setVisibility(View.GONE);
        }

    }

    private float topBarHeight;
    private float vPagerHeight;
    private SDialog singleDialog;


    /**
     * 初始化轮询线程
     */
    private void initBackThread() {

        auctionHandlerThread = new HandlerThread("refresh-auction-list");
        auctionHandlerThread.start();
        auctionHandler = new Handler(auctionHandlerThread.getLooper()) {

            @Override
            public void handleMessage(Message msg) {

//                轮询报价列表
//                refreshBaojiaList(getIntent().getStringExtra("tid"));
                GetAuctionRollback();
            }
        };

    }


    /**
     * 初始化公共部分界面
     *
     * @param brand_name      品牌
     * @param series_name     车系
     * @param spec_name       车型
     * @param channel_name    车商名称
     * @param verank          评估等级
     * @param isacc           是否事故车
     * @param isws            是否水泡车
     * @param isburn          是否火烧车
     * @param mileage         行驶里程
     * @param licdate         上牌日期
     * @param emission        排放标准
     * @param displace        排量
     * @param dispunit        排量单位
     * @param detection_count 检查结果瑕疵数
     */
    private void displayCommonUi(String brand_name, String series_name, String spec_name, String channel_name, String verank,
                                 String isacc, String isws, String isburn, String mileage, String licdate, String emission,
                                 String displace, String dispunit, DetectionCount detection_count, EvaluateDetailResult2.ImageBean imageBean) {

        tvCarDesc.setText(new StringBuffer(brand_name).append(" ").append(series_name).append(" ").append(spec_name).toString());
        tvCompanyName.setText(channel_name);


//        初始化轮播图
        if (null != imageBean) {

            urlList = new ArrayList<>();

            String[] imgPathKey = new String[]{"clzqb", "clzqf", "clyhb", "clzhf", "ybtczg", "qpzy", "hpzy", "zkt", "yb", "fdjc"};

            if (!TextUtils.isEmpty(imageBean.getClzqb())) {
                urlList.add(imageBean.getClzqb());
            }
            if (!TextUtils.isEmpty(imageBean.getClzqf())) {
                urlList.add(imageBean.getClzqf());
            }
            if (!TextUtils.isEmpty(imageBean.getClyhb())) {
                urlList.add(imageBean.getClyhb());
            }
            if (!TextUtils.isEmpty(imageBean.getClzhf())) {
                urlList.add(imageBean.getClzhf());
            }
            if (!TextUtils.isEmpty(imageBean.getYbtczg())) {
                urlList.add(imageBean.getYbtczg());
            }
            if (!TextUtils.isEmpty(imageBean.getQpzy())) {
                urlList.add(imageBean.getQpzy());
            }
            if (!TextUtils.isEmpty(imageBean.getHpzy())) {
                urlList.add(imageBean.getHpzy());
            }
            if (!TextUtils.isEmpty(imageBean.getZkt())) {
                urlList.add(imageBean.getZkt());
            }
            if (!TextUtils.isEmpty(imageBean.getYb())) {
                urlList.add(imageBean.getYb());
            }
            if (!TextUtils.isEmpty(imageBean.getFdjc())) {
                urlList.add(imageBean.getFdjc());
            }

            if (urlList.size() > 0) {
                mAdapter = new ViewPagerAdapter(urlList, this);
                mViewPager.setAdapter(mAdapter);
                tvIndicator.setText(1 + "/" + urlList.size());
                mViewPager.setOnPageChangeListener(this);
            } else {
                mViewPager.setBackgroundResource(R.drawable.er_default_img_select_bkg);
                tvIndicator.setText("0/0");
            }

        }

        HashMap<String, Integer> levelIcon = new HashMap<>();
        levelIcon.put("A", R.drawable.er_icon_level_a);
        levelIcon.put("B", R.drawable.er_icon_level_b);
        levelIcon.put("C", R.drawable.er_icon_level_c);
        levelIcon.put("D", R.drawable.er_icon_level_d);
        levelIcon.put("E", R.drawable.er_icon_level_e);

        if (!TextUtils.isEmpty(verank)) {

            tvIconTextDesc1.setText(String.format("%1$s级", verank));
            ivIconA.setImageResource(levelIcon.get(verank));
        }

        tvIconTextDesc2.setText(isacc.equals("1") ? "重大事故车" : "非重大事故车");
        ivIconB.setImageResource(isacc.equals("1") ? R.drawable.er_icon_accident_true : R.drawable.er_icon_accident_false);

        tvIconTextDesc3.setText(isws.equals("1") ? "水泡车" : "非水泡车");
        ivIconC.setImageResource(isws.equals("1") ? R.drawable.er_icon_sp_true : R.drawable.er_icon_sp_false);

        tvIconTextDesc4.setText(isburn.equals("1") ? "火烧车" : "非火烧车");
        ivIconD.setImageResource(isburn.equals("1") ? R.drawable.er_icon_hs_true : R.drawable.er_icon_hs_false);

        tvDriveMiles.setText(mileage + "万公里");
        tvLicenseTime.setText(TimeUtils.millis2String(Long.valueOf(licdate) * 1000, "yyyy-MM"));
        tvPaifangStandard.setText(emission);
        tvEmission.setText(displace + dispunit);

        if (null != detection_count) {
            if (detection_count.getBodyframe() != 0) {
                tvCsgj.setText(detection_count.getBodyframe() + "处瑕疵");
                tvCsgj.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }

            if (detection_count.getApshell() != 0) {
                tvWg.setText(detection_count.getApshell() + "处瑕疵");
                tvWg.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }

            if (detection_count.getEncomp() != 0) {
                tvFdjc.setText(detection_count.getEncomp() + "处瑕疵");
                tvFdjc.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }

            if (detection_count.getCockpit() != 0) {
                tvJsc.setText(detection_count.getCockpit() + "处瑕疵");
                tvJsc.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }

            if (detection_count.getIgnition() != 0) {
                tvQd.setText(detection_count.getIgnition() + "处瑕疵");
                tvQd.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }
            if (detection_count.getRacing() != 0) {
                tvLs.setText(detection_count.getRacing() + "处瑕疵");
                tvLs.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }
            if (detection_count.getParts() != 0) {
                tvGnxLbj.setText(detection_count.getParts() + "处瑕疵");
                tvGnxLbj.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }

            if (detection_count.getChassis() != 0) {
                tvDp.setText(detection_count.getChassis() + "处瑕疵");
                tvDp.setTextColor(getResources().getColor(R.color.bkg_main_color));
            }
        }
    }

    @Override
    protected void init() {
        setContentView(R.layout.er_activity_xun_jia_detail);
        ButterKnife.bind(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            getWindow().setStatusBarColor(Color.TRANSPARENT);

    }


    @Override
    protected void initView() {

        ivBack.setOnClickListener(this);
        rlCarArchive.setOnClickListener(this);
        rlCsgj.setOnClickListener(this);
        rlWg.setOnClickListener(this);
        rlFdjc.setOnClickListener(this);
        rlJsc.setOnClickListener(this);
        rlQd.setOnClickListener(this);
        rlLs.setOnClickListener(this);
        rlGnxLbj.setOnClickListener(this);
        rlDp.setOnClickListener(this);
        tvCommitPrice.setOnClickListener(this);
        ivBackHome.setOnClickListener(this);
        svDetailDisplay.setOnScrollChangedListener(this);
        topBarHeight = getResources().getDimension(R.dimen.dimen_46);
        vPagerHeight = getResources().getDimension(R.dimen.dimen_250);

//        处理ListView和ScrollView的滑动事件冲突
        lvBaojiaRecord.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    svDetailDisplay.requestDisallowInterceptTouchEvent(false);
                } else {
                    svDetailDisplay.requestDisallowInterceptTouchEvent(true);//屏蔽父控件的拦截事件
                }
                return false;
            }
        });
    }


    @Override
    protected void initData() {

        baojiaRecordList = new ArrayList<>();

        bjRecordAdapter = new BaojiaRecordAdapter(baojiaRecordList, this);
        lvBaojiaRecord.setAdapter(bjRecordAdapter);

        resultType = getIntent().getIntExtra(Constants.DETAIL_RESULT_TYPE, -1);

        if (-1 != resultType) {

            switch (resultType) {
                case Constants.RESULT_TYPE_AUCTION_ON_PROCESS:
                case Constants.RESULT_TYPE_AUCTION_PREPROCESS:
                case Constants.RESULT_TYPE_AUCTION_GOT:
                case Constants.RESULT_TYPE_AUCTION_LOST:
                case Constants.RESULT_TYPE_AUCTION_OTHERS_GOT:

                    loadAuctionResultDetail(getIntent().getStringExtra("tid"));

                    break;

                case Constants.RESULT_TYPE_BAOJIA_WAIT:
                case Constants.RESULT_TYPE_BAOJIA_GAVE:
                case Constants.RESULT_TYPE_BAOJIA_NOT:

                    loadXunjiaResultDetail(getIntent().getStringExtra("rid"));
                    break;

                default:
                    break;
            }

        }

    }

    @Override
    protected void onResume() {

        super.onResume();
        if (null != mViewPager)
            mViewPager.startAutoScroll();

        if (null != auctionHandlerThread && resultType == Constants.RESULT_TYPE_AUCTION_ON_PROCESS) {

            auctionHandler.sendEmptyMessage(CODE_START_LOOP_AUCTION_LIST);
        }
    }


    /**
     * 根据tid加载竞拍结果
     *
     * @param tid
     */
    private void loadAuctionResultDetail(String tid) {

        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("tid", tid);
        Log.e(TAG, "loadAuctionResultDetail: tid :  " + tid);
        ApiClient.postForm(HttpConstants.GET_AUCTION_INFO, params, new RespCallback<AuctionResultDetail>() {
            @Override
            protected void onRequestFailed(String msg) {

                SToast.show(msg);
            }

            @Override
            protected void onSuccess(AuctionResultDetail data) {

                if (null != data) {
                    auctionResultDetail = data;
                    Log.e(TAG, "onSuccess: " + data.getBrand_name() + " state : " + data.getState());

                    if (data.getState().equals("2")) {
                        resultType = Constants.RESULT_TYPE_AUCTION_ON_PROCESS;
                    } else if (data.getState().equals("3")) {
                        resultType = Constants.RESULT_TYPE_AUCTION_PREPROCESS;
                    } else if (data.getState().equals("5")) {
                        resultType = Constants.RESULT_TYPE_AUCTION_LOST;
                    } else if (data.getState().equals("6")) {
                        if (data.getIs_winner() == 1) {
                            resultType = Constants.RESULT_TYPE_AUCTION_GOT;
                        } else {
                            resultType = Constants.RESULT_TYPE_AUCTION_OTHERS_GOT;
                        }
                    }


                    uiRefreshHandler.sendEmptyMessage(1);
                }
            }

            @Override
            public void onBefore(Request request, int id) {
                super.onBefore(request, id);
                showDialog();
            }

            @Override
            public void onAfter(int id) {
                super.onAfter(id);
                dismissDialog();
            }
        });
    }


    /**
     * 根据rid加载询价结果
     *
     * @param rid
     */
    private void loadXunjiaResultDetail(String rid) {

        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("rid", rid);
        Log.e(TAG, "loadAuctionResultDetail:  rid : " + rid);
        ApiClient.postForm(HttpConstants.GET_REFEREN_INFO, params, new RespCallback<XunJiaResultDetail>() {
            @Override
            protected void onRequestFailed(String msg) {
                SToast.show(msg);
            }

            @Override
            protected void onSuccess(XunJiaResultDetail data) {


                if (null != data) {
                    xunJiaResultDetail = data;

                    Log.e(TAG, "onSuccess: 询价状态 ： " + data.getState() + "车辆品牌 ： " + data.getBrand_name());
//                    state=2时，询价中
                    if (data.getState().equals("2")) {

                        if (data.getCallprice() != 0) {
                            resultType = Constants.RESULT_TYPE_BAOJIA_GAVE;
                        } else {
                            resultType = Constants.RESULT_TYPE_BAOJIA_WAIT;
                        }

//                    state=3时，已结束
                    } else if (data.getState().equals("3")) {

                        if (data.getCallprice() != 0) {
                            resultType = Constants.RESULT_TYPE_BAOJIA_GAVE;
                        } else {
                            resultType = Constants.RESULT_TYPE_BAOJIA_NOT;
                        }
                    }

//                    if (data.getCallprice() != 0) {
//                        resultType = Constants.RESULT_TYPE_BAOJIA_GAVE;
//                    } else if(data.getState().equals("")){}
//                    else if ((System.currentTimeMillis() / 1000) > Long.valueOf(data.getEtime())) {
//                        resultType = Constants.RESULT_TYPE_BAOJIA_NOT;
//                    } else if ((System.currentTimeMillis() / 1000) < Long.valueOf(data.getEtime())) {
//                        resultType = Constants.RESULT_TYPE_BAOJIA_WAIT;
//                    }

                    Log.e(TAG, "onSuccess: " + data.getBrand_name());
                    uiRefreshHandler.sendEmptyMessage(2);
                }
            }

            @Override
            public void onBefore(Request request, int id) {
                super.onBefore(request, id);
                showDialog();
            }

            @Override
            public void onAfter(int id) {
                super.onAfter(id);
                dismissDialog();
            }
        });
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
//        设置ViewPager指示器数字
        tvIndicator.setText((position) % urlList.size() + 1 + "/" + urlList.size());
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }


    @Override
    protected void onPause() {
        super.onPause();

//      停止轮询
        if (null != auctionHandler)
            auctionHandler.removeMessages(CODE_START_LOOP_AUCTION_LIST);
    }

    @Override
    protected void onStop() {
        super.onStop();
        mViewPager.stopAutoScroll();
    }


    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.iv_back_home:
                MyApplication.getInstance().removeActivity(this.getClass());
                break;
            case R.id.rl_car_archive:
                Intent intent = new Intent(this, CarArchiveDetailActivity.class);
                if (null != auctionResultDetail) {
                    intent.putExtra("bid", auctionResultDetail.getBid());
                } else if (null != xunJiaResultDetail) {
                    intent.putExtra("bid", xunJiaResultDetail.getBid());
                }
                startActivity(intent);
                break;
            case R.id.rl_csgj:
                startActivityWithIdSeted(R.id.rl_csgj);
                break;
            case R.id.rl_wg:
                startActivityWithIdSeted(R.id.rl_wg);
                break;
            case R.id.rl_fdjc:
                startActivityWithIdSeted(R.id.rl_fdjc);
                break;
            case R.id.rl_jsc:
                startActivityWithIdSeted(R.id.rl_jsc);
                break;
            case R.id.rl_qd:
                startActivityWithIdSeted(R.id.rl_qd);
                break;
            case R.id.rl_gnx_lbj:
                startActivityWithIdSeted(R.id.rl_gnx_lbj);
                break;
            case R.id.rl_ls:
                startActivityWithIdSeted(R.id.rl_ls);
                break;
            case R.id.rl_dp:
                startActivityWithIdSeted(R.id.rl_dp);
                break;

//          提交报价
            case R.id.tv_commit_price:

                switch (resultType) {

                    case Constants.RESULT_TYPE_AUCTION_ON_PROCESS:

                        if (null != auctionResultDetail) {

                            giveAuctionPrice(auctionResultDetail.getTid());

                        }

                        break;

                    case Constants.RESULT_TYPE_BAOJIA_WAIT:

                        if (null != xunJiaResultDetail) {

                            if (TextUtils.isEmpty(etBaojia.getText().toString())) {

                                SToast.show("请输入报价");
                                return;
                            }
                            try {
                                giveBaojia(xunJiaResultDetail.getRid(), StringUtils.getFormatedWith2Bit(Float.valueOf(etBaojia.getText().toString()) * 10000f));
                            } catch (Exception e) {
                                SToast.show("输入格式错误");
                            }

                        }
                        break;

                    default:
                        break;
                }
                break;

            default:
                break;
        }
    }

    /**
     * 轮询数据
     */
    private void GetAuctionRollback() {
        HashMap<String, String> params = new HashMap<>();
        params.put("tid", getIntent().getStringExtra("tid"));
        ApiClient.postForm(HttpConstants.GetAuctionRollback, params, new RespCallback<AuctionRollbackBean>() {
            @Override
            protected void onRequestFailed(String msg) {

            }

            @Override
            protected void onSuccess(AuctionRollbackBean data) {
                //当有人得标
                if (!data.getState().equals("2") || !data.getWin_uid().equals("0") || data.getIs_winner() != 0) {

                    auctionHandler.removeMessages(CODE_START_LOOP_AUCTION_LIST);

                    if (null != auctionHandlerThread)
                        auctionHandlerThread.quit();

                    if (null != mCountDownTask)
                        mCountDownTask.cancel();

                    resultType = Constants.RESULT_TYPE_AUCTION_OTHERS_GOT;
                    loadAuctionResultDetail(getIntent().getStringExtra("tid"));
                } else {
                    if (auctionHandler != null) {
                        //每2秒轮询一次
                        auctionHandler.sendEmptyMessageDelayed(CODE_START_LOOP_AUCTION_LIST, 1000);
                    }

                    baoliu_text.setVisibility(View.VISIBLE);
                    if (Float.valueOf(data.getRprice()) > data.getMax_callprice()) {
                        baoliu_text.setBackgroundResource(R.color.bkg_xing);
                        baoliu_text.setText("未到保留价");
                    } else {
                        baoliu_text.setBackgroundResource(R.color.bkg_blue);
                        baoliu_text.setText("已到保留价");

                    }


                }


                // 刷新报价记录列表
                baojiaRecordList.clear();
                baojiaRecordList.addAll(data.getAcp_list());
                bjRecordAdapter.notifyDataSetChanged();
                if (lvBaojiaRecord.getFirstVisiblePosition() != 0) {
                    lvBaojiaRecord.smoothScrollToPosition(0);
                }
                if (data.getAcp_list().size() > 1) {
                    tvBaojia.setText(StringUtils.getFormatedWith2Bit((data.getAcp_list().get(0).getCallprice() + auctionResultDetail.getIncrease()) / 10000F));
                }

            }

        });

    }

    /**
     * 竞拍-报价
     *
     * @param tid
     */
    private void giveAuctionPrice(final String tid) {

        final HashMap<String, String> params = new HashMap<>();
        params.put("tid", tid);
        final double callprice = StringUtils.mul(Double.parseDouble(tvBaojia.getText().toString()), 10000.00);
        params.put("callprice", StringUtils.getFormatedWith2Bit((float) callprice));
//        if (null != baojiaRecordList && 0 != baojiaRecordList.size() && baojiaRecordList.get(0).getCallprice() != 0) {
//
//            params.put("max_callprice", String.valueOf(baojiaRecordList.get(0).getCallprice() + auctionResultDetail.getIncrease()));
//        } else {
//
//            if (!TextUtils.isEmpty(String.valueOf(auctionResultDetail.getMax_callprice())) && 0 != auctionResultDetail.getMax_callprice())
//                params.put("max_callprice", String.valueOf(auctionResultDetail.getMax_callprice() + auctionResultDetail.getIncrease()));
//            else
//                params.put("max_callprice", String.valueOf(auctionResultDetail.getSprice() + auctionResultDetail.getIncrease()));
//
//        }

//        Log.e(TAG, " ====================== giveAuctionPrice  当前最高报价为 ：  " + params.get("max_callprice"));

        ApiClient.postForm(HttpConstants.SET_AUCTION_CALL_PRICE, params, new StringCallback() {

            @Override
            public void onError(Call call, Exception e, int id) {
                // 网络异常
                if (e instanceof UnknownHostException || e instanceof SocketException) {
                    SToast.show(R.string.tip_network_error, Gravity.CENTER);
                    return;
                }
            }

            @Override
            public void onResponse(String response, int id) {

                try {

                    JSONObject obj = new JSONObject(response);

                    Log.e(TAG, "onResponse: 竞拍返回结果Code值 ： " + obj.optInt("code"));

                    if (obj.optInt("code") == 1) {

                        SToast.show("竞拍报价成功");
                        String s = StringUtils.getFormatedWith2Bit((float) (callprice + auctionResultDetail.getIncrease()) / 10000f);
                        tvBaojia.setText(s);

//                        出价后得标，停止轮询，更新resultType状态，更新界面
                        if (obj.getJSONObject("data").optInt("is_winner", 0) == 1) {

                            auctionHandler.removeMessages(CODE_START_LOOP_AUCTION_LIST);

                            if (null != auctionHandlerThread)
                                auctionHandlerThread.quit();

                            if (null != mCountDownTask)
                                mCountDownTask.cancel();

                            resultType = Constants.RESULT_TYPE_AUCTION_GOT;
                            loadAuctionResultDetail(tid);
                            SToast.show("已得标");

                        } else {
                            SToast.show("报价成功");
                        }


//                    他人得标
                    } else if (obj.optInt("code") == 27) {

                        resultType = Constants.RESULT_TYPE_AUCTION_GOT;
                        loadAuctionResultDetail(tid);

                    } else if (obj.optInt("code") == 0) {
                        showRemind(obj.optString("msg"));
                    } else if (obj.optInt("code") == 38) {
                        showRemind(obj.optString("msg"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onBefore(Request request, int id) {
                showDialog();
            }

            @Override
            public void onAfter(int id) {
                dismissDialog();
            }

        });
    }

    public void showRemind(String remindStr) {

        if (null == singleDialog) {
            singleDialog = new SDialog(this, R.string.t_message_title, remindStr, this, SDialog.TYPE_1_BTN);
        } else {
            singleDialog.setContent(remindStr);
        }
        singleDialog.show();
    }


    /**
     * 询价-报价
     *
     * @param rid
     */
    private void giveBaojia(final String rid, String price) {

        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("rid", rid);
        params.put("callprice", price);

        ApiClient.postForm(HttpConstants.SET_REFERENCE_CALL_PRICE, params, new StringCallback() {

            @Override
            public void onError(Call call, Exception e, int id) {
                // 网络异常
                if (e instanceof UnknownHostException || e instanceof SocketException) {
                    SToast.show(R.string.tip_network_error, Gravity.CENTER);
                    return;
                }
            }

            @Override
            public void onResponse(String response, int id) {

                try {

                    JSONObject obj = new JSONObject(response);

                    if (obj.optInt("code") == 1) {

                        SToast.show("报价成功");
                        tvCommitPrice.setEnabled(false);
                        etBaojia.setEnabled(false);

                        if (null != mCountDownTask)
                            mCountDownTask.cancel();

                        resultType = Constants.RESULT_TYPE_BAOJIA_GAVE;
                        loadXunjiaResultDetail(rid);

                    } else {
                        SToast.show(obj.optString("msg"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onBefore(Request request, int id) {
                showDialog();
            }

            @Override
            public void onAfter(int id) {
                dismissDialog();
            }

        });
    }


    public void startActivityWithIdSeted(int viewId) {
        intent = new Intent(this, CarEvaluateDetailActivity.class);
        intent.putExtra("VIEW_ID", viewId);
        if (null != auctionResultDetail) {
            intent.putExtra("detection", auctionResultDetail.getDetection());
        } else if (null != xunJiaResultDetail) {
            intent.putExtra("detection", xunJiaResultDetail.getDetection());
        }
        startActivity(intent);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mCountDownTask != null) {
            mCountDownTask.cancel();
            mCountDownTask = null;
            Log.e(TAG, "onDestroy:  停止倒计时");
        }

//       停止轮询线程
        if (null != auctionHandlerThread)
            auctionHandlerThread.quit();
    }


    /**
     * 刷新报价列表
     *
     * @param tid
     */
    public void refreshBaojiaList(String tid) {

        HashMap<String, String> params = new HashMap<>();
//        params.put("authkey", UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());
//        params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(), ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
        params.put("tid", tid);

        ApiClient.postForm(HttpConstants.AUCTION_BAO_JIA_LIST, params, new RespCallback<List<BaojiaRecordItem>>() {
            @Override
            protected void onRequestFailed(String msg) {
                SToast.show(msg);
            }

            @Override
            protected void onSuccess(List<BaojiaRecordItem> data) {

                if (null != data && data.size() > 0) {

//                  当前报价有人得标
                    if (data.get(0).getIs_winner() == 1) {

                        auctionHandler.removeMessages(CODE_START_LOOP_AUCTION_LIST);

                        if (null != auctionHandlerThread)
                            auctionHandlerThread.quit();

                        if (null != mCountDownTask)
                            mCountDownTask.cancel();

                        resultType = Constants.RESULT_TYPE_AUCTION_OTHERS_GOT;
                        loadAuctionResultDetail(getIntent().getStringExtra("tid"));

                    }

//                刷新报价记录列表
                    baojiaRecordList.clear();
                    baojiaRecordList.addAll(data);
                    bjRecordAdapter.notifyDataSetChanged();
                    if (lvBaojiaRecord.getFirstVisiblePosition() != 0) {
                        lvBaojiaRecord.smoothScrollToPosition(0);
                    }
                    tvBaojia.setText(StringUtils.getFormatedWith2Bit((data.get(0).getCallprice() + auctionResultDetail.getIncrease()) / 10000F));
                }

//                  每2秒轮询一次
                auctionHandler.sendEmptyMessageDelayed(CODE_START_LOOP_AUCTION_LIST, 2000);
            }
        });
    }


    @Override
    public void onScrollChanged(ScrollView who, int l, int t, int oldL, int oldT) {

        float scrollY = who.getScrollY();
        float topbarOffsetY = vPagerHeight - topBarHeight;

        float offset = 1 - Math.max((topbarOffsetY - scrollY) / topbarOffsetY, 0f);
//      动态改变TopBar透明度
        rlTopBar.setBackgroundColor(Color.argb((int) (offset * 255), 0, 151, 224));

    }

    @Override
    public void onClick(boolean l, View view) {

    }

}
